﻿using DevExpress.XtraEditors;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Inaction.UI
{
    [ProvideProperty("EnableWithEditMode", typeof(BaseListBoxControl))]
    public partial class BarManager : IExtenderProvider
    {
        #region 属性
        [NonSerialized]
        ControlList extendControls = new ControlList();
        #endregion

        #region IExtenderProvider
        public bool CanExtend(object extendee)
        {
            return extendee is BaseListBoxControl;
        }

        [DefaultValue(false)]
        [Category("BarManager")]
        [Description("是否随BarManager.EditMode来设置Enable属性")]
        public bool GetEnableWithEditMode(BaseListBoxControl c)
        {
            return extendControls.Contains(c);
        }
        public void SetEnableWithEditMode(BaseListBoxControl c, bool value)
        {
            if (value)
                extendControls.Add(c);
            else
                extendControls.Remove(c);
        }
        #endregion

        void ApplyControlsExtend()
        {
            foreach (Control c in extendControls)
            {
                var bc = c.BackColor;
                c.Enabled = EditMode;
                c.BackColor = bc;
            }
        }

        class ControlList : CollectionBase
        {
            public int Add(object value)
            {
               return base.List.Add(value);
            }
            public void Remove(object value)
            {
                base.List.Remove(value);
            }
            public bool Contains(object value)
            {
                if (base.List == null) return false;
                return base.List.Contains(value);
            }
        }
    }
}
